<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="author" content="order by dede58.com"/>
    <title>我的购物车-有家书店</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <style>
        html{
            overflow: hidden;
        }
        #box{
            width: 500px;
            margin: 100px auto;
        }
    </style>
</head>
<body>
<div id="box">
    <form class="layui-form" action="">
        <input type="hidden" name="userid" readonly lay-verify="required" value="${sessionScope.dl.userid}" autocomplete="off" class="layui-input">
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" lay-verify="pword" value="${sessionScope.dl.password}" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="password" name="pword" id="pword" lay-verify="pword"  placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">再次输入</label>
            <div class="layui-input-inline">
                <input type="password" name="pword1" id="pword1" lay-verify="pword"  placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="xiugai">修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script src="${pageContext.request.contextPath}/layui/layui.all.js" charset="utf-8"></script>
<script>
    layui.use(['carousel','form','jquery','layer'], function(){
        var carousel = layui.carousel
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;

        /*
        * 表单 的验证
        * */
        form.verify({
            pword: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
        });

        form.on('submit(xiugai)', function(data){
            if (data.field.pword == data.field.password){
                layer.alert("新密码不能和老密码相同", {icon: 5});
            }else if (data.field.pword != data.field.pword1){
                //alert(data.field.pword1);
                layer.alert("输入的两次密码不相同", {icon: 5});
            }else {
                $.ajax({
                    type:'post',
                    url:'${pageContext.request.contextPath}/user/updatePasswordByUserid',
                    data:{"password":data.field.pword,"userid":data.field.userid},
                    dataType:'json',//预期的后台数据类型
                    success:function (data) {
                        if (data.code == "1001"){
                            layer.alert(data.msg, {icon: 1});
                        }else{
                            layer.alert(data.msg, {icon: 5});
                        }
                        setTimeout("top.location.href = '${pageContext.request.contextPath}/khdlogin.jsp'",1500);
                    }
                })
            }
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    });
</script>
</html>
